#ifndef TOOLS_H_
#define TOOLS_H_

#include <string>
#include <vector>
#include <utility>


//! Menny priestor Tools 
/*!
 	Menny priestor zoskopujuci vseobecne funkcie na vykonavanie
	pomocnych operacii nad roznymi datovymi typmi
*/
namespace Tools
{
	//! Separate 
	/*!
 		Funkcia na rozdelenie retazca (std::string) na 2 sub retazce na
		zaklade deliaceho znaku
		\param theInput retazec ktory sa ma rozdelit
		\param theSeparator znak podla ktoreho sa deli
		\param theFirst ak true tak sa pouzije prvy vyskit deliaceho znaku, inak posledny
		\return navrati par(std::pair) sub-retazcov
	*/
	std::pair<std::string, std::string> Separate(std::string theInput,char theSeparator,bool theFirst);
	
	//! Split
	/*!
 		Funkcia na roztrihnutie retazca na n sub-retazcov na zaklade nejakeho deliaceho retazca.
		Pocet sub-retazcov je dany poctom vyskitu deliaceho retazca v vstupnom retazci
		\param theInput retazec ktory sa ma rozdelit
		\param splitBy deliaci retazec
		\return navrati kolekciu (std::vector) sub-retazcov
	*/
	std::vector<std::string> Split(std::string theInput,std::string splitBy);


	std::string GetPath(std::string thePath);


	//! Replace
	/*!
		Funkcia nahradi istu cast v novou castou v objekte typu T 
		\param T& source v ktorom sa ma nahradit 
		\param T what ktory sa nahradi
		\param T with ktory nahradi what
		\return void
	*/
	template<typename T> void Replace(T &source,T what, T with)
	{
		std::size_t aPosition;

		aPosition = source.rfind(what);
		if(aPosition != std::string::npos)
		{
			source.replace(aPosition,what.length(),with);
		}
	}

	template<typename T> void ReplaceAll(T &source,T what, T with)
	{
		std::size_t aPosition;

		for( ;(aPosition=source.find(what))!= std::string::npos;)
		{
			source.replace(aPosition,what.length(),with);
		}

	}

	template<typename T> std::size_t FindNext(std::size_t searchfrom,const T &in_where,const T &what)
	{
		size_t found_pos = 0;

		if( searchfrom >= in_where.size())
			return (found_pos-1);	//to iste ako napr string::npos

		T new_section = in_where.substr(searchfrom);
		
		found_pos = new_section.rfind(what);
		return found_pos;
	}
}


#endif

